package com.wanshi.controller;


import com.wanshi.entity.PasswordReq;
import com.wanshi.entity.Staff;
import com.wanshi.service.IStaffService;
import com.wanshi.utils.Result;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * <p>
 * 员工信息表 前端控制器
 * </p>
 *
 * @author 顽石教育-www.wanshi.com
 * @since 2021-12-16
 */
@RestController
@CrossOrigin
@RequestMapping("/user")
@Api(tags = "测试UserController接口文档")
public class UserController {

    @Autowired
    private IStaffService staffService;

    @ApiOperation(value = "检验原密码是否正确")
    @PostMapping("/pwd")
    public Result chedkpwd(@RequestBody PasswordReq req) {
        return staffService.checkPassowrd(req);
    }

    @ApiOperation(value = "修改用户")
    @PutMapping("/pwd")
    public Result UpdateUser(@RequestBody PasswordReq req) {
        return staffService.UpdatePassword(req);
    }


    @ApiOperation(value = "登陆")
    @PostMapping("/login")
    public Result login(@RequestBody Staff staff) {
        return staffService.login(staff.getUsername(), staff.getPassword());
    }

    @GetMapping("/info")
    public Result getUserInfo(@RequestParam String token){
        return staffService.getUserInfo(token);
    }



    @ApiOperation(value = "注销")
    @PostMapping("/logout")
    public Result logout(){
        return  Result.ok();
    }

}

